<?php

namespace app\v1\controller;

use think\Controller;
use think\Request;
use think\Validate;

/**
 * Class Dynamic
 * @package app\v1\controller
 * 动态模块的控制器
 */
class Dynamic extends Authorization
{
    /**
     * 获取动态列表
     *
     * @return \think\Response
     */
    public function getDynamicList()
    {
        $dynamic=model('v1/Dynamic');
        $dynamic->getDynamicList();
    }

    //提交评论或者回复

    public function addComment(){
        $recordId=input('recordId',0,'int');
        $toUserId=input('toUserId',0,'int');
        $content=input('content',null);
        $validate=new Validate([
            'recordId'=>'require',
            'content'=>'require|min:1|max:300'
        ]);
        $validate->message([
            'recordId.require'=>'动态Id不能为空',
            'content.require'=>'发送内容不能为空',
            'content.max'=>'发送内容不能超过100个字'

        ]);
        $data=$this->request->post();
        if(!$validate->check($data)){
            renderInfo(400001,$validate->getError());
        }
        $dynamic=model('v1/Dynamic');
        $dynamic->addComment($recordId,$toUserId,$content);
    }

    //提交点赞
    public function setPoint(){
        $recordId=input('recordId',0,'int');
        $type=input('type',0,'int');
        $validate=new Validate([
            'recordId'=>'require',
            'type'=>'require'
        ]);
        $validate->message([
            'recordId.require'=>'动态Id不能为空',
            'type.require'=>'操作类型参数不能为空'

        ]);
        $data=$this->request->post();
        if(!$validate->check($data)){
            renderInfo(400001,$validate->getError());
        }
        $dynamic=model('v1/Dynamic');
        $dynamic->setPoint($recordId,$type);
    }

    //删除自己的评论

    public function delComment(){
        $commentId=input('commentId',0,'int');
        $validate=new Validate([
            'commentId'=>'require'
        ]);
        $validate->message([
            'commentId.require'=>'评论Id不能为空'
        ]);
        $data=$this->request->post();
        if(!$validate->check($data)){
            renderInfo(400001,$validate->getError());
        }
        $dynamic=model('v1/Dynamic');
        $dynamic->delComment($commentId);

    }





}
